import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:练习
 * User: cjc
 * Date: 2025-03-09
 * Time: 10:06
 */
public class Test {
    public static void main(String[] args) {
        //test1();
        //test2();
        //test3();
        //test4();
        //test5();
        //test6();
        test7();
    }
    public static void test1() {
        int[] array = {1,2,3};
        Transform(array);
    }
    public static void Transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i]*2;
        }
        System.out.println(Arrays.toString(array));
    }
    public static void test2() {
        int[] array = {1,2,3,4,5,6};
        function(array);
        System.out.println(Arrays.toString(array));
    }
    public static void function(int[] array) {
        int i =0;
        int j = array.length - 1;
        while (i < j) {
            while (i < j && array[i] % 2 != 0) {
                i++;
            }
            while (i < j && array[j] % 2 == 0) {
                j--;
            }
            int temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
    }

    public static int[] func(int[] nums,int target) {
        int[] ret = {-1,-1};
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                if(nums[i] + nums[j] == target) {
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }
    public static void test3() {
        int[] nums = {2,7,11,15};
        int target = 9;
        int[] ret = func(nums,target);
        System.out.println(Arrays.toString(ret));
    }
    public static void test4() {
        int[] array = {4,1,2,1,2};
        int num = 0;
        for (int i = 0; i < array.length; i++) {
            num ^= array[i];
        }
        System.out.println(num);
    }
    public static void test5() {
        int[] array = {2,2,1,1,1,2,2};
        Arrays.sort(array);
        System.out.println(array[array.length/2]);
    }
    public static void test6() {
        int[] arr = {1,2,34,3,4,5,7,23,12};
        boolean flag = Func(arr);
        System.out.println(flag);
    }
    public static boolean Func(int[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]%2!=0) {
                count++;
                if(count == 3) {
                    return true;
                }
            } else {
                count = 0;
            }
        }
        return  false;
    }
    public static void test7() {
        int[] array = {1,3,6,8,9,12,45};
        int[] ret = Blubble(array);
        System.out.println(Arrays.toString(ret));
        int key = 12;
        int index = Erfen(array,key);
        System.out.println(index);
    }
    public static int[] Blubble(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length - 1; j++) {
                if(array[j]>array[j+1]) {
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }
        return array;
    }
    public static int Erfen(int[] array,int k) {
        int i = 0;
        int j = array.length;
        while(i < j) {
            int m = (i+j)/2;
            if(array[m]>k) {
                j = m - 1;
            } else if(array[m]<k) {
                i = m + 1;
            }else {
                return m;
            }
        }
        return -1;
    }
}
